package com.shy.controller;

import com.github.pagehelper.PageInfo;
import com.shy.config.model.R;
import com.shy.entity.Clue;
import com.shy.entity.Customer;
import com.shy.service.CustomerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "客户接口管理")
@RequestMapping("/api/customer")
@RestController
public class CustomerController {

    @Resource
    private CustomerService customerService;

    @ApiOperation("新增客户")
//    @PreAuthorize("hasAuthority('xxx')")
    @PostMapping("/switchCustomer")
    public R<String> saveCustomer(@RequestBody Customer customer) {
        Boolean saved = customerService.saveCustomer(customer);
        return R.HANDLE(saved);
    }
    @ApiOperation("获取客户列表")
    @GetMapping("/pageList")
    public R<PageInfo<Customer>> pageList(@RequestParam Integer current,
                                          @RequestParam(required = false, defaultValue = "10") Integer pageSize) {
        PageInfo<Customer> customerList = customerService.queryCustomerList(current, pageSize);
        return R.success(customerList);
    }

    @ApiOperation("查询客户详情列表")
    @GetMapping("/detail/{id}")
    public R<Customer> detail(@PathVariable Integer id) {
        Customer customer = customerService.queryCustomerById(id);
        return R.success(customer);
    }
}